package com.example.livetempogara;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;

public class ModControlloActivity extends Activity {
	ListView listView;
	ArrayAdapter<String> arrayAdapter;
	ThreadUpdate th;
	boolean stop;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_mod_controllo);
		stop=false;
		listView = (ListView)findViewById(R.id.listViewTags);
        String [] array = {" "};
        arrayAdapter = new ArrayAdapter<String>(this, R.layout.row, R.id.textViewList, array);
        listView.setAdapter(arrayAdapter);
        
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.mod_controllo, menu);
		return true;
	}
	
	public void connect(View v) throws InterruptedException{
		
//			while(stop==false){
			EditText edText = (EditText) findViewById(R.id.editTextIp);
			String ip = edText.getText().toString();
			ApplicationData appData = (ApplicationData) getApplication();
			appData.c = new Controller(ip, 0);
			EditText edTextR = (EditText) findViewById(R.id.editTextRefresh);
			String r = edTextR.getText().toString();
			if(edTextR.getText().length()>0)
				appData.c.refresh = new Integer(r);
			th = new ThreadUpdate(this);
	        th.execute();
//	        Thread.sleep(3000);
//		}
	}
	
	public void modificaRefresh(View v){
		ApplicationData appData = (ApplicationData) getApplication();
		if(appData.c!=null){
			EditText edRef = (EditText) findViewById(R.id.editTextRefresh);
			String textRefresh = edRef.getText().toString();
			appData.c.refresh= new Integer(textRefresh);
		}
	}
	
	public void pause(View v){
		ApplicationData appData = (ApplicationData) getApplication();
		if(appData.c!=null)
			appData.c.pause=!appData.c.pause;
		Button b = (Button) findViewById(R.id.buttonPausa);
		if(b.getText().equals("Pause"))
			b.setText("Start");
		else
			b.setText("Pausa");
	}

}
